﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using DefeatEpidemic.Models;

namespace DefeatEpidemic.Models
{
    public class DefeatEpidemicContext : DbContext
    {
        public DbSet<Member> Members { get; set; }

        public DbSet<Resource> Resources { get; set; }

        public DbSet<Record> Records { get; set; }

        public DbSet<Log> Logs { get; set; }

        public DbSet<Family> Families { get; set; }

        public DbSet<Car> Cars { get; set; }

        public DbSet<Application> Applications { get; set; }

        public DbSet<WxOauth> Wxoauths { get; set; }

        public DbSet<Manager> Managers { get; set; }

        public DbSet<CheckRecord> checkRecord { get; set; }

        private IConfiguration configuration;

        public DefeatEpidemicContext()
        {
            configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();
        }

        public DefeatEpidemicContext(DbContextOptions<DefeatEpidemicContext> options)
            : base(options)
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            //optionsBuilder.UseSqlite(configuration.GetConnectionString("db"));
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            
            //modelBuilder.Entity<Member>(entity =>
            //{
            //    entity.ToTable("Members");
            //    entity.HasOne(x => x.community).WithMany(r => r.members).OnDelete(DeleteBehavior.SetNull);
            //});
            
        }
        public DbSet<DefeatEpidemic.Models.Community> Community { get; set; }
    }
}
